package com.sa.web.front.action;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

import javax.servlet.ServletContext;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class DownLoadStuInfo extends ActionSupport {
	
	private String fileName;
	
	private String url;
	
	public String downLoadStuInfo() throws Exception{
		return SUCCESS;
	}

	public InputStream getInputStream() throws Exception{
		InputStream is = null;
		try{
		ActionContext ac = ActionContext.getContext(); 
		ServletContext sc = (ServletContext) ac.get(ServletActionContext.SERVLET_CONTEXT); 
		String path = sc.getRealPath("stuFile");
		is = new FileInputStream(path + url);
		}catch(Exception e){
			e.printStackTrace();
		}
		return is;
	}
	
	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getFileName() {
		try {
			return URLDecoder.decode(fileName,"UTF-8");
		} catch (UnsupportedEncodingException e) {
			return "";
		}
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public static void main(String[] args){
		
		try {
			new FileInputStream("C:\\14.jpg");
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
